<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/vectrics.tld" prefix="vectrics" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>


<%@ page import="org.vectrics.recruiter.config.RecruitConfig" %>
<%@ page import="org.vectrics.recruiter.job.Job" %>
<%@ page import="org.apache.log4j.Logger" %>
<%@ page import="org.vectrics.recruiter.config.*" %>
<%@ page import="org.vectrics.recruiter.job.*" %>
<%@ page import="org.vectrics.company.*" %>
<%@ page import="org.vectrics.provider.*" %>

<%@ page import="java.util.*" %>
<%@ page import="org.vectrics.recruiter.struts.admin.AdminJobForm" %>
<%@ page import="org.vectrics.hibernate.*" %>
<%@ page import="org.vectrics.recruiter.*" %>

<jsp:useBean id="jobStatusForm" class="org.vectrics.recruiter.struts.JobStatusForm" scope="request"/>

<vectrics:errors debug="false"/>
<%
	Logger log = Logger.getLogger(this.getClass());
	
	log.debug("getting params");
	//Job job = (Job)request.getAttribute("job");
	//String jobId = job.getId().toString();
	//String locationId = null;
	//String functionCode = null;
	String companyId = null;
	String domainId = null;
	companyId = (String)request.getAttribute("companyId");


	log.debug("finding job");
/*
	if (job != null)  {
		log.debug("finding location");
		if (job.getLocation() != null) {
			log.debug("location is not null");
			locationId = job.getLocation().getId().toString();
			if (job.getFunction() != null)
				functionCode = job.getFunction().getCode();
		}
		if (companyId == null) {
			if (job.getCompany() != null) {
				companyId = job.getCompany().getId().toString();
			}
		}
		
	}
	
	Company company = CoreServiceLocator.getCompanyService().findCompany(new Long(companyId));
	*/
	domainId = ThreadProperties.getDomain().getId().toString();
	
	String summary = request.getParameter("summary");
	Boolean canChangeStatus = (Boolean)request.getSession().getAttribute("canChangeStatus");
	Collection notAuthJobStatusTypes = (Collection)request.getSession().getAttribute("jobStatusTypesNotAuth");
	boolean hasNotAuthStatuses = false;
%>


<html:form action="/admin/jobs/savestatus" method="POST" focus="statusTypeCode">
	<html:hidden property="companyId"/>
	<html:hidden property="jobId"/>

	<table>
		<tr>
			<td valign="TOP">
				<table width="600" cellpadding="4" cellspacing="1">
					<tr>
						<td class="formBg2">
							<font class="stdFont"><bean:message key="prompt.job.company"/></font>
						</td>
						<td class="formBg2">
							<font class="stdFont"><bean:write name="jobStatusForm" property="companyName"/></font>
						</td>
					</tr>				
		
					<tr>
						<td class="formBg1" valign="top">
							<font class="formLabelClass"><bean:message key="prompt.job.reference.id"/></font>
							<vectrics:errors property="referenceId"/>
						</td>
						
						<td class="formBg1" valign="top">
							<font class="stdFont"><bean:write name="jobStatusForm" property="referenceId"/></font>
						</td>
					</tr>
					<tr>
						<td class="formBg2" valign="top" width="50%">
							<font class="formLabelClass"><bean:message key="prompt.job.function"/></font>
							<vectrics:errors property="functionCode"/>
						</td>
						<td class="formBg2" valign="top" width="50%">
							<font class="stdFont"><bean:write name="jobStatusForm" property="functionDescription"/></font>
						</td>
					</tr>
			

					<tr>
						<td class="formBg1" valign="top">
							<font class="formLabelClass"><bean:message key="prompt.job.title"/></font></td>
						<td class="formBg1" valign="top">
							<font class="stdFont"><bean:write name="jobStatusForm" property="title"/></font>
						</td>
					</tr>

<%        if (canChangeStatus.booleanValue()) { %>
					<tr>
						<td class="formBg2" valign="top"><font class="formLabelClass"><bean:message key="prompt.job.status"/></font></td>
						<td class="formBg2" valign="top">
							<html:select name="jobStatusForm" property="statusTypeCode" styleClass="formComboClass">
							  <html:options collection="jobStatusTypes" labelProperty="description" property="code"/>
							</html:select>
				<%
					if (hasNotAuthStatuses) { 
						       out.write("<font class=\"subFont\"><br><b>Not authorized for:</b></font><br>");
						       Iterator iter = notAuthJobStatusTypes.iterator();
						       while (iter.hasNext()) {
						       		JobStatusType jobStatusType = (JobStatusType)iter.next();
				 					        out.write("<font class=\"subFont\">");
				 					        out.write(jobStatusType.getDescription(request.getLocale()));
				 					        out.write("</font>");
				 					        if (iter.hasNext())
				 					            out.write("<br>");
							   }
									
						   }
				%>
				         </td>
				  </tr>
      <%   } else {			%>
					<tr>
						<td class="formBg2">
							<font class="stdFont"><bean:message key="prompt.job.status"/></font>
						</td>
						<td class="formBg2">
							<font class="stdFont"><bean:write name="jobStatusForm" property="statusDescription"/>
								<br><i>Not Authorized to Change Status</i></font>
						</td>
					</tr>				
<%		}	%>
					<tr>
						<td valign="TOP" align="left"></td>
						<td valign="TOP" align="left">
							<vectrics:formButton elementId="ok.btn" code="button.ok" phraseCode="button.ok" value="submit" name="submit"/>&nbsp;
							<vectrics:formButton elementId="cancel.btn" code="button.cancel" phraseCode="button.cancel" value="cancel" name="cancel"/>
						</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
</html:form>